package com.zhouchao.user.controller;

import com.zhouchao.user.common.Result;
import com.zhouchao.user.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @Author: zhouchao
 * @Date: 2021/10/15 19:28
 * @Description:
 */
@RestController
@RequestMapping("api/user")
public class UserController {

    @Autowired
    private IUserService lagouAuthCodeService;

    @GetMapping("register/{email}/{password}/{code}")
    public Integer register(@PathVariable String email, @PathVariable String password, @PathVariable String code) {
        return lagouAuthCodeService.register(email, password, code).getData();
    }

    @GetMapping("isRegistered/{email}")
    public Result<Boolean> isRegistered(@PathVariable String email) {
        return lagouAuthCodeService.isRegistered(email);
    }

    @GetMapping("login/{email}/{password}")
    public String login(@PathVariable String email, @PathVariable String password, HttpServletRequest request, HttpServletResponse response) {
        Result<String> login = lagouAuthCodeService.login(email, password, request, response);
        return login.getData();
    }

    @GetMapping("info/{token}")
    public String getInfo(@PathVariable String token) {
        return lagouAuthCodeService.getInfo(token).getData();
    }
}
